package com.example.erat.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.erat.entity.Experiment;
import com.example.erat.mapper.ExperimentMapper;
import com.example.erat.service.ExperimentService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ExperimentServiceImpl extends ServiceImpl<ExperimentMapper, Experiment> implements ExperimentService {

    @Override
    public List<Experiment> getExperimentsByCourseId(String courseId) {
        LambdaQueryWrapper<Experiment> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Experiment::getCourseId, courseId)
               .orderByDesc(Experiment::getPublishDate);
        return this.list(wrapper);
    }

    @Override
    public Experiment getExperimentDetail(String experimentId) {
        // 基础信息查询
        Experiment experiment = this.getById(experimentId);
        
        // 可扩展查询关联信息，如课程名称等
        // ...
        
        return experiment;
    }

    @Override
    public boolean isExperimentOverdue(String experimentId) {
        Experiment experiment = this.getById(experimentId);
        if (experiment == null || experiment.getDeadline() == null) {
            return false;
        }
        return new Date().after(experiment.getDeadline());
    }
}    